package com.flot.yazb.module.test;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.flot.yazb.R;
import com.flot.yazb.ChannelManage;
import com.flot.yazb.base.adapter.recycleview.BRAdapter;
import com.flot.yazb.base.adapter.recycleview.RVAdapter;
import com.flot.yazb.base.adapter.recycleview.RvHolder;
import com.flot.yazb.base.BActivity;
import com.flot.yazb.model.other.ZCModel;
import com.flot.yazb.widget.utils.ToastUtil;
import com.flot.yazb.widget.MRecycleView;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BActivity {

    @BindView(R.id.mrv)
    MRecycleView mRecycleview;
    private List<ZCModel> dataList = new ArrayList<>();
    private BRAdapter<ZCModel> rvAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        ChannelManage.getChannel(this);
        createData();
        createAdapter();
    }

    private void createAdapter() {
        mRecycleview.setLayoutManager(new LinearLayoutManager(this));
        mRecycleview.setRefreshProgressStyle(ProgressStyle.BallScaleMultiple);//刷新样式
        mRecycleview.setLoadingMoreProgressStyle(ProgressStyle.BallSpinFadeLoader);//加载样式

        mRecycleview.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                //refresh data here
                ToastUtil.showToast(MainActivity.this, "refresh");
                mRecycleview.refreshComplete();

            }

            @Override
            public void onLoadMore() {
                // load more data here
                mRecycleview.loadMoreComplete();
                ToastUtil.showToast(MainActivity.this, "onLoadMore");
            }
        });


        rvAdapter = new BRAdapter<ZCModel>(this, R.layout.activity_fatelist_item, dataList) {

            @Override
            protected void convert(RvHolder holder, ZCModel ZCModel, int position) {
//                holder.setText(R.id.tv, ZCModel.value);
            }
        };

        rvAdapter.setOnItemClickListener(new RVAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                ToastUtil.showToast(MainActivity.this, "onItemClick: " + position + "---" + dataList.get(position).value);
            }

            @Override
            public void onItemLongClick(View v, int position) {
                ToastUtil.showToast(MainActivity.this, "onItemLongClick: " + position + "---" + dataList.get(position).value);
            }
        });

        mRecycleview.setAdapter(rvAdapter);
    }

    private void createData() {
        for (int k = 0; k < 25; k++) {
            ZCModel kv = new ZCModel();
            kv.key = k + "";
            kv.value = "item  的值是  " + k;
            dataList.add(kv);
        }
    }

    public void setCheckFragment(){
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
    }

}
